# -*- coding:UTF-8 -*-


from nd_utils.matplotlib_helper import *
import matplotlib.pyplot as plt

# import numpy as np
# import  pandas as pd
#
# N=5
# y=[20,10,30,25,15]
# index = np.arange(N)
# #p1=plt.bar(index,y,width=0.5,color='b') #条形图 left昨天横坐标 高度height color为颜色，width为宽度 垂直
# plt.bar(index, y, width=0.5 ,color='b')#s水平直方图
# plt.show()

import numpy as np

# index = np.arange(4)
# sales_BJ=[52,55,63,53]
# sales_SH=[44,66,55,41]
# bar_width=0.3
#
# plt.bar(index,sales_BJ,bar_width,color='b') #sales_BJ直方图
# # plt.bar(index+bar_width,sales_SH,bar_width,color='r') #叠加sales_SH的直方图（主要是加一个bar_width）图1
# #
# plt.bar(index,sales_SH,bar_width,color='r',bottom=sales_BJ) #叠加sales_SH的层叠图 图2
#
# plt.show()

def plt_precision_recall_f1_bar(author_name_list, precision_list, recall_list, f1_list):
    num = len(precision_list)
    index = np.arange(0, num, step=1)
    bar_width = 0.2
    p1 = plt.bar(index, precision_list, bar_width, color='b' )
    p2 = plt.bar(index + bar_width, recall_list, bar_width, color='r')
    p3 = plt.bar(index + 2*bar_width, f1_list, bar_width, color='g')

    # plt.xticks(index, author_name_list, style='oblique', horizontalalignment='left', rotation='-30')
    # plt.xticks(index, author_name_list ,horizontalalignment='left', rotation='-18')
    plt.xticks(index, author_name_list ,horizontalalignment='left', rotation='0')
    plt.yticks(np.arange(0, 1.1, 0.1))

    plt.legend( (p1[0], p2[0], p3[0]), ('precision', 'recall', 'f1'))
    save_fig(plt, 'precision_recall_f1_fig')
    plt.show()

def plt_baseline_our_method_f1(author_name_list, baseline_f1, our_method_f1):
    num = len(baseline_f1)
    index = np.arange(0, num, step=1)
    bar_width = 0.2
    # plt.grid()
    p1 = plt.bar(index, baseline_f1, bar_width, color='b')
    p2 = plt.bar(index + bar_width, our_method_f1, bar_width, color='r')

    plt.xticks(index, author_name_list, horizontalalignment='left', rotation='-18')
    plt.yticks(np.arange(0, 1.1, 0.1))
    # plt.title("pa")
    plt.legend((p1[0], p2[0]), ('baseline method', 'our method'))
    save_fig(plt, 'baseline_our_f1_fig')
    plt.show()


from nd_utils.read_csv import read_csv_f

def main1():
    author_name_list, precision_list, recall_list, f1_list = read_csv_f("name_disam")

    plt = plt_precision_recall_f1_bar(author_name_list, precision_list, recall_list, f1_list)

def main2():
    author_name_list = ['Cheng Chang','Wen Gao', 'Jie Tang','Jing Zhang', 'Kuo Zhang',
                        'Bin Yu', 'Bing Liu', 'Hui Fang', 'Ajay Gupta', 'Michael Wagner', 'Rakesh Kumar', 'Lei Wang', 'avg']

    baseline_f1 = [0.774193548, 0.778122335, 0.817123288, 0.392971246, 0.610169492, 0.51734104, 0.555296857,
                    0.52345679, 0.5, 0.598857143, 0.843055556, 0.286567164, 0.599762872 ]

    our_method_f1 = [0.691099476, 0.971844898, 0.982497775, 0.697931034, 0.84375, 0.685279188,
                    0.739152564, 0.723684211, 0.69527897, 0.774322969, 0.966743497, 0.785797893, 0.79644854]

    plt = plt_baseline_our_method_f1(author_name_list, baseline_f1, our_method_f1 )

def main3():
    heuristic_cluster_rule = ['coauthor_feature', 'org_venue_feature']
    avg_precision_list = [    0.865947422,0.79154311 ]

    avg_recall_list = [     0.748430191, 0.497213217]

    avg_f1_list = [    0.793554272, 0.600542109]

    plt = plt_precision_recall_f1_bar(heuristic_cluster_rule, avg_precision_list, avg_recall_list, avg_f1_list)

if __name__ == '__main__':
    # author_name_list = ['Jing Zhang', 'Bin Yu', 'Rakesh Kumar', 'Lei Wang', 'Bin Li']
    #
    # precision_list = [0.933579336, 0.835913313, 0.996605567, 0.735573411, 0.81552306]
    #
    # recall_list = [0.557268722, 0.580645161, 0.938618926, 0.843383585, 0.886308068]
    #
    # f1_list = [0.697931034, 0.685279188, 0.966743497, 0.785797893, 0.849443468]
    #
    # plt = plt_precision_recall_f1_bar(author_name_list, precision_list, recall_list, f1_list)

    # main2()
    # main1()
    main3()

"""
https://matplotlib.org/gallery/lines_bars_and_markers/bar_stacked.html#sphx-glr-gallery-lines-bars-and-markers-bar-stacked-py

"""






